<html>
<head><meta charset="utf-8"><title>equivalent of `io::Write` that&#x27;s string-oriented? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html">equivalent of `io::Write` that&#x27;s string-oriented?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209959343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209959343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209959343">(Sep 14 2020 at 01:59)</a>:</h4>
<p><code>std::io::Write</code> seems to be byte-oriented:</p>
<blockquote>
<p>A trait for objects which are byte-oriented sinks.</p>
</blockquote>
<p>and it also is not implemented by <code>String</code>. Is there an equivalent trait that is <code>String</code>-oriented and that <code>String</code> implements? Thanks!</p>



<a name="209959563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209959563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209959563">(Sep 14 2020 at 02:05)</a>:</h4>
<p>It looks like pulldown-cmark <a href="https://docs.rs/pulldown-cmark/0.8.0/pulldown_cmark/escape/trait.StrWrite.html">has something like this</a>. Maybe there's a case for adding it to std?</p>



<a name="209959719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209959719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209959719">(Sep 14 2020 at 02:08)</a>:</h4>
<p><a href="https://doc.rust-lang.org/std/fmt/trait.Write.html">https://doc.rust-lang.org/std/fmt/trait.Write.html</a></p>



<a name="209959737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209959737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209959737">(Sep 14 2020 at 02:09)</a>:</h4>
<p>(maybe pulldown should use that too?)</p>



<a name="209959744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209959744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209959744">(Sep 14 2020 at 02:09)</a>:</h4>
<p>Although it says:</p>
<blockquote>
<p>This trait should generally not be implemented by consumers of the standard library. The write! macro accepts an instance of io::Write, and the io::Write trait is favored over implementing this trait.</p>
</blockquote>



<a name="209959913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209959913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209959913">(Sep 14 2020 at 02:14)</a>:</h4>
<p>Cc <span class="user-group-mention" data-user-group-id="2645">@T-libs</span></p>



<a name="209960771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209960771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209960771">(Sep 14 2020 at 02:38)</a>:</h4>
<p>Oops, didn't realize pinging in this context was bad etiquette. Sorry about that!</p>



<a name="209967449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209967449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209967449">(Sep 14 2020 at 05:57)</a>:</h4>
<p>I’m not sure why that comment is there. I’ve used <code>fmt::Write</code> for general-purpose Unicode-based streams.</p>



<a name="209969796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209969796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209969796">(Sep 14 2020 at 06:47)</a>:</h4>
<p>Writing to a String using <code>write_str</code> is fastest, so there's absolutely no reason to shy away from fmt::Write if that is indeed what you're doing.</p>



<a name="209969862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/209969862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#209969862">(Sep 14 2020 at 06:48)</a>:</h4>
<p>And if you must use a write_fmt method, then write_fmt for a String is preferable over write_fmt to a <code>Vec&lt;u8&gt;</code></p>



<a name="210084916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/equivalent%20of%20%60io%3A%3AWrite%60%20that%27s%20string-oriented%3F/near/210084916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/equivalent.20of.20.60io.3A.3AWrite.60.20that&#x27;s.20string-oriented.3F.html#210084916">(Sep 15 2020 at 02:28)</a>:</h4>
<p>Opened <a href="https://github.com/rust-lang/rust/issues/76729">#76729</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>